package com.hxd.otc.module.my.presenter;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.my.contract.ModifyMoneyPasswordContract;
import com.hxd.otc.module.my.model.UserModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.EncryptUtils;

/**
 * Created by lzy on 2018/6/12 0012.
 * description ${修改交易密码}
 */
public class ModifyMoneyPasswordPresenter extends BasePresenter<ModifyMoneyPasswordContract.View> implements ModifyMoneyPasswordContract.Presenter {

    private final UserModel mUserModel;

    public ModifyMoneyPasswordPresenter(ModifyMoneyPasswordContract.View view) {
        super(view);
        mUserModel = UserModel.getInstance();
    }

    @Override
    public void resetMoneyPassword(String loginPassword,String payPassword, String verCode) {
        mUserModel.updateExPassword(loginPassword,payPassword, verCode, new BaseObserver<String>() {
            @Override
            public void onNext(String msg, String o) {
                mView.resetMoneyPasswordSuccess();
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }

    @Override
    public void setMoneyPassword(String loginPassword,String payPassword, String verCode) {
        mUserModel.updateExPassword(EncryptUtils.getRSA(loginPassword), EncryptUtils.getRSA(payPassword),verCode, new BaseObserver<String>() {
            @Override
            public void onNext(String msg, String o) {
                mView.setMoneyPasswordSuccess();
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }

    @Override
    public void getVerCode() {
        mUserModel.sendExValidTypeMobileSms( "ex_password", new BaseObserver<String>() {

            @Override
            public void onNext(String msg, String o) {
                mView.startCountdown();
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }

        }, mView.<BaseBean<String>>bindAutoDispose());
    }

}
